package com.zs.diveinspringboot

import org.springframework.context.ApplicationEvent
import org.springframework.context.annotation.AnnotationConfigApplicationContext

/**
 * Spring 应用事件引导类
 * @description
 * @author madison
 * @date 2021/6/5 17:50
 *
 */
class SpringApplicationEventBootstrap

fun main(array: Array<String>) {
    // 创建上下文
    val context = AnnotationConfigApplicationContext()
    //注册应用事件监听器
    context.addApplicationListener { event -> println("监听到事件:$event") }
    //启动上下文
    context.refresh()
    context.publishEvent("HelloWorld")
    context.publishEvent("2021")
    context.publishEvent(object : ApplicationEvent("madison") {})
    //关闭上下文
    context.close()
}